import {getLogger} from "log4js"
import {Handler} from "./Handler"
import {MethodInterceptor} from "./_MethodInterceptor"

export default class HandlerExecutionChain {
  private static logger = getLogger("HandlerExecutionChain")

  private interceptorList: NullAble<MethodInterceptor[]>

  handler: NullAble<Handler>

  handle(req: HttpRequest, res: HttpResponse): any {
    this.applyPreHandle(req, res)
    return this.invokeHandle(req, res)
  }

  applyPreHandle(req: HttpRequest, res: HttpResponse) {

  }

  applyPostHandle(req: HttpRequest, res: HttpResponse) {

  }

  invokeHandle(req: HttpRequest, res: HttpResponse) {
    return this.handler.handlerExecutor(req, res)
  }

  constructor(handler) {
    this.handler = handler
  }
}
